#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QMouseEvent>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 只有将这个选项设为true，Qt才会追踪鼠标移动的位置
//    this->setMouseTracking(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    // 获取鼠标点击按钮
    if(event->button() == Qt::LeftButton)
    {
        qDebug() << "按下鼠标左键";
    }
    else if(event->button() == Qt::RightButton)
    {
        qDebug() << "按下鼠标右键";
    }
    else if(event->button() == Qt::MidButton)
    {
        qDebug() << "按下鼠标滚轮";
    }
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << event->x() << ", " << event->y();
}

void Widget::wheelEvent(QWheelEvent *event)
{
    qDebug() << event->delta();
}
